package crudfx.field;
import crudfx.interop.*;
import crudfx.data.*;
import javax.swing.*;
import javax.swing.event.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class NumberField extends UIComponent{
    protected var jSpinner:JSpinner;
    var model:SpinnerNumberModel;
    public var value:Number=0 on replace{model.setValue(value);};
    public var stepSize:Number=0.1 on replace {model.setStepSize(stepSize);};
    public var min:Number=-1000.0 on replace {model.setMinimum(min);};
    public var max:Number=1000.0 on replace {model.setMaximum(max);};
    init{
        jSpinner=new JSpinner();
        if(value<min)value=min;
        if(value>max)value=max;
        model=new SpinnerNumberModel(value.doubleValue()
            ,min.doubleValue()
            ,max.doubleValue()
            ,stepSize.doubleValue());
        jSpinner.setModel(model);
        var listener:ChangeListener=ChangeListener{
            override function stateChanged(e:ChangeEvent){
                value=model.getNumber().doubleValue() as Number;
                }
            }
        model.addChangeListener(listener);
        }
    override public function getJComponent():JComponent{
        return jSpinner;
        }
    override public function highlight(s:String):Boolean{
        return false;
        }
    override public function gather():DataTree{
        var me:DataTree=DataTree{ name:"NumberField" };
        me.node("value").asNumber(0).value=value;
        return me;
        }
    }

